function objToPrams(obj, key, encode) {
    if (obj==null) return '';
    let paramStr = '';
    const t = typeof (obj);
    if (t == 'string' || t == 'number' || t == 'boolean') {
        paramStr += '&' + key + '='  + ((encode==null||encode) ? encodeURIComponent(param) : param);
    } else {
        for (var i in param) {
            var k = key == null ? i : key + (param instanceof Array ? '[' + i + ']' : '.' + i)
            paramStr += urlEncode(param[i], k, encode)
        }
        paramStr.slice(1)
    }
    return paramStr;
}

function navigateTo(page, params, callback) {
    const paramStr = !params ? '' : objToPrams(params);
    const url = '/pages/' + page + '/' + page + paramStr;
    wx.navigateTo({
        url: url,
        success: callback,
        fail: function(error) {
            wx.showToast({
                title: error,
                icon: 'none',
                duration: 2000,
                mask: false
            });

        }
    })
}

module.exports = {
    navigateTo
}
